#if !defined( DYN_MATRIX_H)
#define  DYN_MATRIX_H
#include <algorithm>
#include <istream>
#include <deque>
#include <assert.h>
using std::string;

template <typename T> class t_dynamic_matrix_template
{
private:
	T default_value;
	std::deque< std::deque<T> > matrix;
public:

	t_dynamic_matrix_template(const T& default_value_)
		:default_value(default_value_){}
	
	const T& at(unsigned i, unsigned j) const
	{
		if (matrix.size() <= i ||
			matrix[i].size() <= j)
			return default_value;
		return matrix[i][j];
	}
	
	void resize(unsigned i, unsigned j)
	{
		unsigned m = std::max(i, j) + 1;
		if (matrix.size() <= m)
			matrix.resize(m, std::deque<T>());
			
		if (matrix[i].size() <= j)
			matrix[i].resize(j + 1, default_value);
		if (matrix[j].size() <= i)
			matrix[j].resize(i + 1, default_value);
	}
	
	void set(unsigned i, unsigned j, const T& t)
	{
		resize(i,j);
		matrix[i][j] = t;
	}
};



typedef t_dynamic_matrix_template<double> t_dynamic_matrix;
typedef t_dynamic_matrix_template<bool> t_dynamic_matrix_bool;
/*
unsigned read_matrix_from_stream_in_fasta_pairs_format(	std::istream& infile,
														t_dense_matrix_f& matrix,
														t_dense_matrix_bool& missing_values,
														std::vector<std::string>& names,
														std::string& cluster_name,
														unsigned& missing_values,
														unsigned& duplicate_values,
														double default_value = 10000.0);

unsigned read_matrix_from_vector_of_pairs_format(		std::vector<std::string>::const_iterator begin,
														std::vector<std::string>::const_iterator end,
														t_dense_matrix_f& matrix,
														t_dense_matrix_bool& missing_values,
														std::vector<std::string>& names,
														unsigned& missing_values,
														unsigned& duplicate_values,
														double default_value = 10000.0);

*/
#endif	// DYN_MATRIX_H

